package ink.ykb.configClient.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 测试：
 * post http://127.0.0.1:8881/bus/refresh 或 http://127.0.0.1:8881/refresh 均可
 * @author dell
 *
 */
//这个注解用于刷新@Value注入的配置，否则需要使用Environment
@RefreshScope
@RestController
public class HiController {
  
  private static final Logger LOG = LoggerFactory.getLogger(HiController.class);

	@Autowired
	private Environment env;
	
	@Value("${foo}")
	private String foo;
	
    @RequestMapping(value = "/hi")
    public String hi(String test){
      String result = "foo参数："+foo+"  env foo参数："+env.getProperty("foo")+"=========>"+test;
      LOG.info("result："+result);
        return result;
    }
    
    @RequestMapping(value = "/test/error")
    public String error(){
      throw new RuntimeException("这是测试异常错误");
    }
}
